package com.woniuxy.service.impl;

import com.woniuxy.entity.DiseaseTags;
import com.woniuxy.mapper.DiseaseTagsMapper;
import com.woniuxy.service.DiseaseTagsService;
import com.woniuxy.util.ResponseEnum;
import com.woniuxy.util.ResponseUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 疾病标签服务实现类
 * 实现疾病标签相关的业务逻辑
 */
@Service
@Transactional
public class DiseaseTagsServiceImpl implements DiseaseTagsService {
    @Resource
    private DiseaseTagsMapper mapper;
    
    /**
     * 查询所有疾病标签
     * @return 返回所有疾病标签的响应结果
     */
    @Override
    public ResponseUtil queryAll() {
        List<DiseaseTags> diseaseTags = mapper.queryAll();
        return diseaseTags.size() > 0 ? ResponseUtil.get(ResponseEnum.OK,diseaseTags)
                : ResponseUtil.get(ResponseEnum.FAIL);
    }

    /**
     * 根据居民ID查询疾病标签（用于测试）
     * @return 返回指定居民的疾病标签信息
     */
    @Override
    public ResponseUtil queryByResidentId() {
//        String ids = mapper.queryDiseaseIdByResidentId(1);
//        String names = mapper.queryDiseaseNameByResidentId(1);
//        List<Integer> idsList = Arrays.stream(ids.split(","))
//                .map(String::trim)//方法引用
//                .map(Integer::parseInt)
//                .collect(Collectors.toList());
//        List<String> namesList = Arrays.asList(names.split(","));
//        Object[] idsArray = idsList.toArray();
//        Object[] namesArray = namesList.toArray();
//
//        List<DiseaseTags> diseaseTags = new ArrayList<>();
//        for (int i = 0; i < idsArray.length; i++) {
//            DiseaseTags tag = new DiseaseTags();
//            tag.setDiseaseId((Integer) idsArray[i]);
//            tag.setDiseaseName((String) namesArray[i]);
//            diseaseTags.add(tag);
//        }
//        return diseaseTags != null ? ResponseUtil.get(ResponseEnum.OK,diseaseTags)
//                : ResponseUtil.get(ResponseEnum.FAIL);
        return null;
    }


}
